package com.example.springmvcdemo2.respone;

import lombok.*;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {

    private Integer code;

    private String msg;

    private Object data;

    public JsonResult(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
    }

    public JsonResult(StatusCode statusCode,Object data) {
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = data;
    }

//    public JsonResult(Object data){
//        this.code = StatusCode.SUCCESS.getCode();
//        this.msg = StatusCode.SUCCESS.getMsg();
//        this.data = data;
//    }

    /**
     * 成功(不带数据)
     */
    public static JsonResult ok(){
        return new JsonResult(StatusCode.SUCCESS);
        // return JsonResult.ok(null);
    }

    /**
     * 成功(带数据)
     */
    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.SUCCESS,data);
        //return new JsonResult(data);
    }

}

